#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

const int N = 100010;

int n;
int a[N];
int ans = 0;

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a, a + n);
    for (int i = 0; i < n; ++i)
        ans += abs(a[i] - a[n / 2]);
    cout << ans;
    return 0;
}